import { React, useState, useEffect } from 'react';
import request from "../../utils/request"
import moment from 'moment'
import {
    Form,
    Input,
    Button,
    Radio,
    Select,
    Cascader,
    DatePicker,
    InputNumber,
    TreeSelect,
    Switch,
    Row,
    Col,
    message
} from 'antd';
function Add(props) {
    console.log("props", props);
    const dataqqq = { ...props.data };
    // delete dataqqq._id;
    dataqqq.birth = moment(dataqqq.birth, 'YYYY-MM-DD')
    const [form] = Form.useForm()
    console.log(dataqqq);
    form.setFieldsValue({ ...dataqqq })
    // useEffect(function () {
    //     return function () {
    //         console.log(111111);
    //         dataqqq = {}
    //         console.log('用法四：useEffect返回一个函数')
    //     }
    // }, [])


    function onFinish(values) {

        request.put("/student/updata", { data: values }).then((res) => {
            console.log("res", res);
            if (res.data.code == 200) {
                message.success('学生信息更新成功')
                // form.setFieldsValue('')
                // form.resetFields('')
            } else {
                message.success('学生信息更新失败')
            }
        })
    }
    return (
        <>
            <h2 style={{ fontSize: 30, textAlign: 'center' }}>学生信息修改</h2>

            <Form
                labelCol={{
                    span: 8,
                }}
                wrapperCol={{
                    span: 8,
                }}
                form={form}
                onFinish={onFinish}
            // initialValues={{ ...dataqqq }}
            >
                <Form.Item label="学号" name="userid" rules={[{ required: true, message: '请输入学号!' }]}>
                    <Input disabled />
                </Form.Item>
                <Form.Item label="姓名" name="username" rules={[{ required: true, message: '请输入姓名!' }]}>
                    <Input />
                </Form.Item>
                <Form.Item label="出生日期" name="birth" rules={[{ required: true, message: '请输入出生年月日!' }]}>
                    <DatePicker />
                </Form.Item>
                <Form.Item label="性别" name="sex">
                    <Select>
                        <Select.Option value="男">男</Select.Option>
                        <Select.Option value="女">女</Select.Option>
                    </Select>
                </Form.Item>
                <Form.Item label="联系电话" name="phone">
                    <Input />
                </Form.Item>
                <Form.Item label="学院" name="college">
                    <Input />
                </Form.Item>
                <Form.Item label="专业" name="major">
                    <Input />
                </Form.Item>
                <Form.Item label="班级" name="garde">
                    <Input />
                </Form.Item>
                <Form.Item label="寝室号" name="dormitory">
                    <Input />
                </Form.Item>
                <Row >
                    <Col span={3} offset={9}>
                        <Form.Item>
                            <Button htmlType="submit">修改</Button>

                        </Form.Item>
                    </Col>
                    <Col span={3} offset={0}>
                        <Form.Item>
                            <Button onClick={() => { console.log(123); }} >取消</Button>
                        </Form.Item>
                    </Col>

                </Row>
            </Form>
        </>
    )
}
export default Add